<?php

class AppController extends Controller {

	var $helpers = array('Javascript','Html');
	var $components = array('Acl', 'Auth');

	/**
	 * beforeRender
	 *
	 * Application hook which runs after each action but, before the view file is
	 * rendered
	 *
	 * @access public
	 */
	function beforeRender(){
		//If we have an authorised user logged then pass over an array of controllers
		//to which they have index action permission
		#parent::beforeFilter();
		$base  = FULL_BASE_URL . $this->webroot;
		$this->set(compact('base'));
		$this->www_root = WWW_ROOT;
		
	}

	function beforeFilter() {
		if ((Router::url("", true)) == (FULL_BASE_URL . $this->webroot)){
			if ($this->Auth->user('id') == 1){
				//$this->redirect(array('plugin'=>'news','controller'=>'news','action'=>'index'));
			}else{
				//$this->redirect(array('controller'=>'webs','action'=>'index'));
			}
		}
		 
		if ((Router::url("", true)) == (FULL_BASE_URL . $this->webroot.'productos/users/login')){
			$this->redirect(FULL_BASE_URL . $this->webroot.'users/login');
		}
		 
		//Configure AuthComponent
		$this->Auth->actionPath = 'controllers/';
		$this->Auth->authorize = 'actions';
		$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
		$this->Auth->logoutRedirect = array('controller' => 'webs', 'action' => 'index');
		$this->Auth->loginRedirect = array('controller'=>'webs','controller' => 'productos', 'action' => 'index');
	}
}